const state = {
    products: [{
            name: '苹果',
            price: 200
        },
        {
            name: '香蕉',
            price: 400
        },
        {
            name: '橘子',
            price: 600
        },
        {
            name: '菠萝',
            price: 800
        }
    ]
};
const getters = {
    saleProducts: (state) => {
        let saleProducts = state.products.map(product => {
            return {
                name: product.name,
                price: product.price / 2
            }
        })
        return saleProducts; // 注：这里是重新返回了一个对象
    }
};
const mutations = {
    minusPrice(state, payload) {
        state.products.forEach(product => {
            product.price -= payload;
        })
    }
};
const actions = {
    minusPriceAsync(context, payload) {
        setTimeout(() => {
            context.commit('minusPrice', payload);
        }, 1000)
    }
};
export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}